package com.bml.architect.sentinel.config;

import com.alibaba.csp.sentinel.adapter.servlet.CommonFilter;
import com.alibaba.csp.sentinel.annotation.aspectj.SentinelResourceAspect;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.sql.PreparedStatement;

/**
 * @author: baiml
 * @Title: SentinelConfig
 * @ProjectName: 中台技术平台
 * @Depart 中台研发部
 * @Description:只和spring一起使用，不用自动装配
 * @date: 2021/4/20 11:43
 */
//@Configuration
public class SentinelConfig {

    /**
     * 原生的sentinel使用，通过aop来实现
     * @return
     */
//    @Bean
//    public SentinelResourceAspect sentinelResourceAspect(){
//
//        return new SentinelResourceAspect();
//    }

    /**
     * 添加配置类，配置CommonFilter过滤器，指定WEB_CONTEXT_UNIFY=false，禁止收敛URL的入口context
     * @return
     */
    @Bean
    public FilterRegistrationBean sentileRegistrationBean(){
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(new CommonFilter());
        registration.addUrlPatterns("/*");
        // 入口资源关闭聚合   解决流控链路不生效的问题
        registration.addInitParameter(CommonFilter.WEB_CONTEXT_UNIFY,"false");
        registration.setName("sentinelFilter");
        registration.setOrder(1);
        return registration;
    }


}
